<?php
require_once 'AbstractParseMessage.class.php';

class FileParseMessage extends AbstractParseMessage {
    private $currentClass = null;
    private $currentFunction = null;

    public function reveive($title, $message) {
        switch( $title ) {
            case 'setFileName':
                $this->name = $message;
                break;
            case 'addComment':
                $this->addComment(intval($message));
                break;
            case 'addLines':
                $this->addLines();
                break;
            case 'enterClass':
                $this->addStatInArray('classes', array(), $message['name']);
                $this->currentClass = $message['name'];
                break;
            case 'addExtends':
            case 'addImplements':
            case 'addMethodTypeHint':
            case 'addFunctionTypeHint':
            case 'addStaticReference':
            case 'addNewClassReference':
            case 'addCatchClassReference':
                $this->addStatInArray('references', $message, $message);
                break;
            case 'enterFunction':
                $this->stats['functions'][$message['function']] = $message;
                $this->currentFunction = $message['function'];
                break;
            case 'addCyclo':
                $this->incStats('cyclo', 1);
                break;
            case 'variableSuperglobal':
                $this->incStats('superglobal',1);
                break;
            case 'addInclude':
                $this->addStatInArray('include', $message);
                break;
            case 'functionStat':
                $this->stats['functions'][$message['function']]['stats'] = $message['stats'];
                break;
            case 'classStat':
                $this->stats['classes'][$message['class']] = $message['stats'];
                break;
        }
    }

    public function reset() {
        parent::reset();
        $this->currentClass = null;
        $this->currentFunction = null;
        $this->setStatValue('cyclo', 0);
        $this->setStatValue('superglobal', 0);
        $this->setStatValue('classes', array());
        $this->setStatValue('functions', array());
        $this->setStatValue('references', array());
        $this->setStatValue('include', array());
    }

    public function setFilename($filename) {
        $this->reset();
        $this->name = $filename;
        $this->setStatValue('file', $filename);
    }



}